package com.Web.servlet;

import com.alibaba.fastjson2.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/ServlectName")
public class ServlectName extends HttpServlet {


        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
            //设置内容类型
            resp.setContentType("application/json;charset=utf-8");
            String Name = req.getParameter("Name");
            List<Student> students = JDBCUtils.query(Student.class, "select * from student where name like ?", "%" + Name + "%");
            //转换数据为JSON格式
            String str = JSON.toJSONString(students);
            //响应流发送数据给用户
            resp.getWriter().write(str);
        }
}
